package com.alibaba.wallet.service;

import com.alibaba.api.pojos.Trade;
import com.alibaba.api.service.TradeServiceApi;
import com.alibaba.wallet.mapper.TradeMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service(version = "1.0.0")
public class TradeServiceImpl implements TradeServiceApi {

    @Autowired
    private TradeMapper tradeMapper;

    @Override
    public List<Trade> findById(Long id) {
        QueryWrapper<Trade> wrapper = new QueryWrapper<>();
        wrapper.eq("account_id", id);
        List<Trade> trades = tradeMapper.selectList(wrapper);
        return trades;
    }

    @Override
    public boolean insert(Trade trade) {
        trade.setTradeTime(new Date());
        return tradeMapper.insert(trade) == 1;
    }
}
